package cn.tedu.csmall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;

/**
 * ClassName: ValidationConfiguration
 * Package: cn.tedu.csmall.product.config
 * Description 快速失败配置类
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/12/1
 */
@Configuration
@Slf4j
public class ValidationConfiguration {
    public ValidationConfiguration() {
        log.debug("创建配置类对象：ValidationConfiguration");
    }

    @Bean
    public javax.validation.Validator validator() {
        return Validation.byProvider(HibernateValidator.class)
                .configure()// 开始配置
                .failFast(true)// 配置快速失败
                .buildValidatorFactory()// 构建Validator工厂
                .getValidator();// 从Validator工厂中获取Validator对象

    }
}